Private Declare Function SetPixel Lib "gdi32" Alias "SetPixelV" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal crColor As Long) As Long
Private Declare Function GetNearestColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long
Private Const COLOR_HIGHLIGHT = 13
Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNSHADOW = 16
Private Const COLOR_BTNTEXT = 18
Private Const COLOR_BTNHIGHLIGHT = 20
Private Const COLOR_BTNDKSHADOW = 21
Private Const COLOR_BTNLIGHT = 22
Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Long) As Long
Private Declare Function GetBkColor Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetTextColor Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Private Const DT_CALCRECT = &H400
Private Const DT_WORDBREAK = &H10
Private Const DT_CENTER = &H1 Or DT_WORDBREAK Or &H4
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function FrameRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function DrawFocusRect Lib "user32" (ByVal hdc As Long, lpRect As RECT) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Const PS_SOLID = 0
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Const RGN_DIFF = 4
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function InflateRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function CopyRect Lib "user32" (lpDestRect As RECT, lpSourceRect As RECT) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBTRIPLE
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBTRIPLE
End Type
Public Enum ButtonTypes
[Windows 16-bit] = 1 'the old-fashioned Win16 button
[Windows 32-bit] = 2 'the classic windows button
[Windows XP] = 3 'the new brand XP button totally owner-drawn
[Mac] = 4 'i suppose it looks exactly as a Mac button... i took the style from a GetRight skin!!!
[Java metal] = 5 'there are also other styles but not so different from windows one
[Netscape 6] = 6 'this is the button displayed in web-pages, it also appears in some java apps
[Simple Flat] = 7 'the standard flat button seen on toolbars
[Flat Highlight] = 8 'again the flat button but this one has no border until the mouse is over it
[Office XP] = 9 'the new Office XP button
'[MacOS-X] = 10 'this is a plan for the future...
[Transparent] = 11 'suggested from a user...
[3D Hover] = 12 'took this one from "Noteworthy Composer" toolbal
[Oval Flat] = 13 'a simple Oval Button
[KDE 2] = 14 'the great standard KDE2 button!
End Enum
Public Enum ColorTypes
[Use Windows] = 1
[Custom] = 2
[Force Standard] = 3
[Use Container] = 4
End Enum
Public Enum PicPositions
cbLeft = 0
cbRight = 1
cbTop = 2
cbBottom = 3
cbBackground = 4
End Enum
Public Enum fx
cbNone = 0
cbEmbossed = 1
cbEngraved = 2
cbShadowed = 3
End Enum
Private Const FXDEPTH As Long = &H28
'events
Public Event Click()
Attribute Click.VB_UserMemId = -600
Attribute Click.VB_MemberFlags = "200"
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event KeyPress(KeyAscii As Integer)
Public Event KeyDown(KeyCode As Integer, Shift As Integer)
Public Event KeyUp(KeyCode As Integer, Shift As Integer)
Public Event MouseOver()
Public Event MouseOut()
'variables
Private MyButtonType As ButtonTypes
Private MyColorType As ColorTypes
Private PicPosition As PicPositions
Private SFX As fx 'font and picture effects
Private He As Long 'the height of the button
Private Wi As Long 'the width of the button
Private BackC As Long 'back color
Private BackO As Long 'back color when mouse is over
Private ForeC As Long 'fore color
Private ForeO As Long 'fore color when mouse is over
Private MaskC As Long 'mask color
Private OXPb As Long, OXPf As Long
Private useMask As Boolean, useGrey As Boolean
Private useHand As Boolean
Private picNormal As StdPicture, picHover As StdPicture
Private pDC As Long, pBM As Long, oBM As Long 'used for the treansparent button
Private elTex As String 'current text
Private rc As RECT, rc2 As RECT, rc3 As RECT, fc As POINTAPI 'text and focus rect locations
Private picPT As POINTAPI, picSZ As POINTAPI 'picture Position & Size
Private rgnNorm As Long
Private LastButton As Byte, LastKeyDown As Byte
Private isEnabled As Boolean, isSoft As Boolean
Private HasFocus As Boolean, showFocusR As Boolean
Private cFace As Long, cLight As Long, cHighLight As Long, cShadow As Long, cDarkShadow As Long, cText As Long, cTextO As Long, cFaceO As Long, cMask As Long, XPFace As Long
Private lastStat As Byte, TE As String, isShown As Boolean 'used to avoid unnecessary repaints
Private isOver As Boolean, inLoop As Boolean
Private Locked As Boolean
Private captOpt As Long
Private isCheckbox As Boolean, cValue As Boolean
Private Sub OverTimer_Timer()
If Not isMouseOver Then
OverTimer.Enabled = False
isOver = False
Call Redraw(0, True)
RaiseEvent MouseOut
End If
End Sub
Private Sub UserControl_AccessKeyPress(KeyAscii As Integer)
LastButton = 1
Call UserControl_Click
End Sub
Private Sub UserControl_AmbientChanged(PropertyName As String)
Call SetColors
Call Redraw(lastStat, True)
End Sub
Private Sub UserControl_Click()
If LastButton = 1 And isEnabled Then
If isCheckbox Then cValue = Not cValue
Call Redraw(0, True) 'be sure that the normal status is drawn
UserControl.Refresh
RaiseEvent Click
End If
End Sub
Private Sub UserControl_DblClick()
If LastButton = 1 Then
Call UserControl_MouseDown(1, 0, 0, 0)
SetCapture hwnd
End If
End Sub
Private Sub UserControl_GotFocus()
HasFocus = True
Call Redraw(lastStat, True)
End Sub
Private Sub UserControl_Hide()
isShown = False
End Sub
Private Sub UserControl_Initialize()
'this makes the control to be slow, remark this line if the "not redrawing" problem is not important for you: ie, you intercept the Load_Event (with breakpoint or messageBox) and the button does not repaint...
isShown = True
End Sub
Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyDown(KeyCode, Shift)
LastKeyDown = KeyCode
Select Case KeyCode
Case 32 'spacebar pressed
Call Redraw(2, False)
Case 39, 40 'right and down arrows
SendKeys "{Tab}"
Case 37, 38 'left and up arrows
SendKeys "+{Tab}"
End Select
End Sub
Private Sub UserControl_KeyPress(KeyAscii As Integer)
RaiseEvent KeyPress(KeyAscii)
End Sub
Private Sub UserControl_KeyUp(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyUp(KeyCode, Shift)
If (KeyCode = 32) And (LastKeyDown = 32) Then 'spacebar pressed, and not cancelled by the user
DrawRectangle 1, 1, Wi - 2, He - 2, ShiftColor(cFace, -&H9), True
DrawRectangle 2, 2, Wi - 4, 2, cHighLight
DrawRectangle 2, 4, 2, He - 6, cHighLight
Call DrawCaption(6)
End Select
Call DrawPictures(2)
End If
End With
If isOver And MyColorType = Custom Then BackC = tempCol: SetColors
End Sub
Private Sub DrawRectangle(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal Color As Long, Optional OnlyBorder As Boolean = False)
'this is my custom function to draw rectangles and frames
'it's faster and smoother than using the line method
Dim bRECT As RECT
Dim hBrush As Long
bRECT.Left = X
bRECT.Top = Y
bRECT.Right = X + Width
bRECT.Bottom = Y + Height
hBrush = CreateSolidBrush(Color)
If OnlyBorder Then
FrameRect UserControl.hdc, bRECT, hBrush
Else
FillRect UserControl.hdc, bRECT, hBrush
End If
DeleteObject hBrush
End Sub
Private Sub DrawEllipse(ByVal X As Long, ByVal Y As Long, ByVal Width As Long, ByVal Height As Long, ByVal BorderColor As Long, ByVal FillColor As Long)
Private Sub DrawLine(ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal Color As Long)
'a fast way to draw lines
Dim pt As POINTAPI
Dim oldPen As Long, hPen As Long
With UserControl
hPen = CreatePen(PS_SOLID, 1, Color)
oldPen = SelectObject(.hdc, hPen)
MoveToEx .hdc, X1, Y1, pt
LineTo .hdc, X2, Y2
SelectObject .hdc, oldPen
DeleteObject hPen
End With
End Sub
Private Sub DrawFrame(ByVal ColHigh As Long, ByVal ColDark As Long, ByVal ColLight As Long, ByVal ColShadow As Long, ByVal ExtraOffset As Boolean, Optional ByVal Flat As Boolean = False)
'a very fast way to draw windows-like frames
Dim pt As POINTAPI
Dim frHe As Long, frWi As Long, frXtra As Long
frHe = He - 1 + ExtraOffset: frWi = Wi - 1 + ExtraOffset: frXtra = Abs(ExtraOffset)
Ihe t t(XPFace,(eTranslm, rc2, DT_CEN 6i, HO F((-SHe XF, DT_CEN 6i, HO F((-erst If isOverampersandPos Ae) rc.RigeO F((-SHe XFi - 2F En TE rc: OffsetRect rc2, 1, 1
Call CalcPicPos 'once we have the tex m As i cFa6uS cFaceex To'Select Case Sta3Dra[4x, LecFaceB, DT_CENTER
alcPicPos 'asic rule is that if an ammN ERcDEetRect rc2, 1, 1Sub
Private Sub nslm, rc2, DT_CEN 6i, HDunctie, ShiftColor(XPFace, --&u1)
--&u1)
2yrc2.fsetRrawText Userc
Pri'ivang TER
Aave the tex m As Bent in certain ar_ tex m As i-ivang TO ReceODisXeger XP button i use a work-aroud that work i use ShiftColor(OXPf, -&H20) + Abs(MyC 6i, HDunctie, ShiftColor(rPAos 'asic rule is that if an ammN ERcDEetRect(en
cFace = &Hk-aroudd ub 'chOXPf, -fsetRra1, DT_rule is SeC
rc.RigeOObjeck i d Fpngle 2, 4, 2, He -2, Fice XPZRight dSube teght dSube teght dSube teght dSc .hdex, i, he buttoig rule is S- 3, Wi - 4, He -pic teght dSc .hdex, i, he buttoig rule 3DawText Userc
Pri'ivang y rule 3DawTeBackC)
cFac$ 3DawTt3ange everame cHighLight, cDarkShadow, cLight, cShadow, Fs1Wi i'c2.Left = 1 + picSZ.X: rc2.RColor(rPAos 'asic rule is tShadowthe AsA1ork i use ShiftColor(OXPuttoig rule is S- 3, Wi - 4, He -pic teg=G ysi, W have the tex m A,irule base to build
nCaptionHr(ampersandPos + 2, (- D 0 ' EngHe - Wi - 4,1en isShown = False: prevBTt3ange everase: prevBTt3ange everase: prevBTt3ange<> 2 Then DrawTexmN ERcDEetR'dteght dSuGe(eTrang O F((-SHe -&H20, B D 0 ' EngHe - Wi - 4,1en igHe - Wi 1 = CreateRectRgn(Wi, He, Wi - 1, He - 1)
N ERcDEetR'dteght dS0Dd Select
#@#@#@etRect(en
cFace = &Hk-aroudd aptionHr(ampersandPos +g thd aptionHreck i d Fpngle 2, 4, 2, He -2, Fice XPZRi - 3, Case 1
cFace = &Hk-aroudd CassssSenNor
= ShiftHe TER
i, w, cLmsaSelect
'we now draw the text that is common in all traw th E 2 disabled
A w, ceHreck i d FpnglA w, ceHreck i d FpnglA w, ceHreck i d FpnglAion (rs
aaud that workivatop.ht d ShiftCol0 :E, -&H. sooonal B
nHr(ampersandPos +g thd apti draw d FpnglA w, c XP bu'we ncLmsaSe Call DoFXY: rcS, i, he buttoig Tran lTex,SP To HeChadowb===lor \ &H1wO.
a7e=n BTnex,S. sooona 4,1en iFpnglAion (rs m Asc XP bu'we ncLmsaSe LmsaSeleoona etRec
Privatop = C Ene'we ncLmhisnHr(amB HeChadowbos 'once wnEb)
ne Wi - tDRight dSuen iFpnglAf ex, ampersandPos + 1, 1))
= ' fw, c w, c Tlo buitText, ( etTextC lText, -stepXP1 * i)E If Color(OX((th
Plor sssSe c , c w, c-stetepXP1 * i unType SXwRectaf iase 9 'Office XP
arch like this would 3 OXPb = GetSysColdc, cFteoonpXP- 9 'Office XP' fw, c w, c Tlo bu d ShiftCol0 o5 'WinsssSene To Hould 3 OXPb = GetSysColdce XP' t, ( ShiftC OXPb ===================================preB\ 2
If Not isXP t rgn1
thd aptionHrectCol0 :E, -&H- 2=================
ce XP
Oo-&H. sooonal B
nHr(ampat workivatCnd &HFCase
' so2.TopY: rc2.Bo.TopYLong
===============
OrawRecta
OrawRecta
OraeV As L000) Mod &H101nglA w, ceHreck i d FpnglAion (rs
aaud that worHtM
OraeV As L000) ModWinssm, rc2, DT_C
Private Sub nslm, rc2,'n (rs
aaud that /5 Fse ShiftColor(OXPf, -&H2iu Fse ShiftColor(Oe 0, 0ftColor
Copn .hd.RigeO (P$e
i XP bu'we ncLms a6l0uon (rsor
Copn .hd.RigeO B searching for another poso'Select Case Sta3Dra[4x, LecFaceO = cFace
r(c D5 le ampersand is drawn and this is not the acce 2, (He - rc.Bottom -r3.hsdeO (P$ laccH, Shi00) ModWinssm, rc2, DT_C
Private0, 0, Wi, He)
End Selemobd &buiOe 0, 0ftCBottomIBa
Copn en(eu+ Abs(MyC 6i, HDunctie, 40), True
1 ' (so'Select Case Sta3Dra[4:3i,Sub (amB Hem1 ' (si m A,irule base to build
nCaptionHr(ampersandPos + 2, (- D 0 ' EngH mc, rc2: faeV As PtRgn(or
ue to 9siya(e)
ooon - ub 'chOXPf,lklsCasesb i =i, (- e
t, (or
ight, -stepXP1 * i)
t, -stepXP10, 0ftCBottomI
i DrawRecta m A,iR'dteght dSuGe(e5F EngH mc Fpngle 2, Sub SetColors()
'this functioru,iR'dteght dSuGe, ( SetCIfunctioru,iBottomIFH mc Fpn (or
ight, t it looks too l Wi, He)
X rc
#@#@#@etRecP t e5F EngH mc Fpngle 2, Sub SetColors()
'this fk0Tlo b i Draw CombineRgn pXP1 2, He - 2, cShadow
S .hd.i D He - 1, ShiftCols1 2H mc Fpn (urc.Rightx, Leght dSuGe(e5F EngH mc Fpngle 2, Sub SetColors()
'this functioru,iR'dteght dSuGe, ( SetB
ud If'HPos, HeevBcght, t it looks toooMe) is my custom function to draw rectangles and frames
'it's faster and smoother than using theaption(2)XectRgn(Wng, ByVal and smoothn.ledSc .hdeand e acce 2, (He - rc.Braw rectangt 6i, He,A,iR'dteght dSuGe(A1ectBTn 2 Then DrawTexmN Eihis ft 6i, H+Fe, 40), True
C5p Sub SetCols functioruA,iR'd Cswoks too l Wi, He)
X rcFetCols functioruA,iR'd Cswo, 0ftCBottomI
i DrawRecta m A,iR'ds Ae) rc.RigeO F((Dim ReceODietSys"PFalse: prevBTtMyColAsc (Wng, ByVal,iRRRRRRRRRRRRRRRRRevBT S .nc,i Case 1:/Col0 :E, -&H. sooonal BShiftHe TER
i, w, cLmsaSelect
'we now draw the text th3 = &HB0) As Longo'Se, ByVa 1, 1))
Red ud I - 1, Shie pi'eF SetTextColor .hdc, cHigheutColor.RigeO B searching for another poso'Select Cas2=I - tlHighe(reck Call DeleteObject(SelectObject(hdc, pPen))
epeu DeleteCase 1:igh Cas, -ssssss ule iP - 2, He - ==Xighe(rA w, ceHreck i d, 1, Wi - 3, He - colors taken as a base to b He - ==Xighe Sub Se2- w, c D